﻿@model Rehabilitation.Models.Patient
@using Rehabilitation.Models;

@{
    ViewBag.Title = "Details";
}

<h2>Details</h2>

<fieldset>
    <legend>Patient</legend>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.DateOfBirth)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.DateOfBirth)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.FirstName)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.FirstName)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.LastName)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.LastName)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.Sex)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Sex)
    </div>
</fieldset>
<p>
    @Html.ActionLink("Edit", "Edit", new { id=Model.PatientID }) |
    @Html.ActionLink("Back to List", "Index")
</p>

<div>
    Tests: @Html.ActionLink("Create New", "Create", "Test", new{id = ((Patient)ViewBag.Patient).PatientID}, null)<br/>
    @if(ViewBag.Tests ==null || !((List<Test>)ViewBag.Tests).Any())
    {
        <text>
        The Patient did not take any test yet.
        </text>
    }else
    {
        List<Test> tests = (List<Test>) ViewBag.Tests;
        <text>
            <table class="full">
                <thead>
                    <tr>
                        <td>Test Date</td>
                        <td>Location</td>
                        <td>User</td>
                        <td>Operations</td>
                    </tr>
                </thead>
                <tbody>
                    @foreach(Test test in tests)
                    {
                        Location location = new Location();
                        User user = new User();
                        using(DBEntities db = new DBEntities())
                        {
                            location = db.Locations.Single(l => l.LocationID == test.Location);
                            user = db.Users.Single(u => u.UserId.Equals(test.UserID));
                        }
                        <text>
                        <tr>
                            <td>@test.TestDate.ToString("MMM dd, yyyy")</td>
                            <td>@location.DisplayName</td>
                            <td>@user.UserName</td>
                            <td>
                                @Html.ActionLink("Edit", "Edit","Test", new { id = test.TestID }, null) |
                                @Html.ActionLink("Details", "Details", "Test", new { id = test.TestID }, null) |
                                @Html.ActionLink("Delete", "Delete", "Test", new { id = test.TestID }, null)
                            </td>
                        </tr>
                        </text>
                    }
                </tbody>
            </table>
        </text>
    }

</div>
